home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / misc / vpan100.zip / SU_T-DEP.CPP < prev    next >
C/C++ Source or Header  |  1995-01-19  |  8KB  |  322 lines

  1. //
  2. //    AC SUSCEPTEMETER
  3. //
  4. //           T-DEPENDANCE MEASUREMENT
  5. //
  6. //     BUTTON AND PAINT PROCEDURES (bp and pp)
  7. //
  8. //                       |     Written by O.Rasizade
  9. //                 |       (c) Oct 1992, 1993
  10. //                       |
  11. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  12. #include <vphead.h>    // must be included first
  13. #pragma hdrstop
  14.  
  15. #include <vpbase.h>
  16. #include <vpinbox.h>
  17. #include <vpindic.h>
  18. #include <vpgraph.h>
  19. #include <vpbutt.h>
  20. #include <vputil.h>
  21.  
  22. #include <suscept.h>
  23. #include "su_bp.h"
  24. //----------------- DECLARATIONS --------------
  25. char  find_ch(char c); // defined in su_hystb.cpp
  26.  
  27. //-------------------- GLOBAL VARIABLES -------------
  28. indbutton *pbutHeat1;
  29. _Indicator *indN1;
  30. extern Indicator<double> *indDC,*indDisbal,*indModule;
  31. extern indbutton *butHeater;
  32. extern Board *Tdependance;
  33. extern FILE *dat;
  34. extern char nameTdepDat[];    // name of data file
  35. int N1=1,statusTdep=11;
  36. int heatIntensity=1;
  37.  
  38. double minT=77.,maxT=170.,step=.1;
  39. float _maxT=170.,_minT=77.;
  40. int counter=1;
  41.     //---------------------- BACKGROUND PROCEDURE ---------
  42.  
  43. void far  TdepBackgr(void)
  44. {
  45. static float trigT;
  46. //---------------------- GRAPH SECTION ---
  47. static float Temp0,a10,b10;
  48. static double ac_a1=0.,ac_b1=0.,ac_Temp=0.;
  49. static n=0;
  50.  
  51.  Graph<float,float>  grTdep1(
  52.     x0s,y0s,PERM,nameTdepDat,
  53.     15,12,    /* number of x & y div.            */
  54.     25,20,    /* number of pixels in every div.    */
  55.  
  56.     _minT,-2.5,    /* values of x,y at origin    */
  57.     (_maxT-_minT)/15.,5./12.,    /* values of x,y div.        */
  58.                       // Hereafter defaults are used
  59.     procDummy,
  60.     "Temperature","A1(red) B1(yellow)",    /* text on the axises*/
  61.     "%.1f","%.2f");             /* format of values on divisions*/
  62.  grTdep1.OnScreen=1;
  63.  measureA1B1T();
  64.  updateIndicators();
  65.  
  66.  switch (statusTdep)
  67.  {
  68.   case 0:               //--- Init
  69.        if (InitTdep()==-1)
  70.         {
  71.          DisplayErrorMessage("Cannot create data file");
  72.          statusTdep=10;
  73.          }
  74.        else
  75.         {
  76.          grTdep1.Paint();
  77.          grTdep1.PutDot(Temp,a1,RED);
  78.          grTdep1.PutDot(Temp,b1,YELLOW);
  79.          Temp0=Temp; a10=a1; b10=b1;
  80.          trigT=Temp+step; statusTdep=1;
  81.         }
  82.         break;
  83.   case 1:
  84.       if ( (Temp>maxT) || (Temp<minT) )
  85.          statusTdep=10;             // end measurement
  86.       else
  87.        {
  88.         ac_a1+=a1; ac_b1+=b1; ac_Temp+=Temp;
  89.         n++;
  90.         indN1->Put(n);
  91.         if ((Temp>=trigT && step>0) || (Temp<=trigT && step<0))
  92.          {
  93.           a1=ac_a1/n ; b1=ac_b1/n ; Temp=ac_Temp/n;
  94.           fprintf( dat, "\n%.2f %.3f %.3f", Temp, a1, b1);
  95.           n=0; ac_a1=0; ac_b1=0; ac_Temp=0;
  96.           grTdep1.PutLine(Temp0,a10,Temp,a1,RED);
  97.           grTdep1.PutLine(Temp0,b10,Temp,b1,YELLOW);
  98.           a10=a1; b10=b1;
  99.           Temp0=Temp;
  100.           trigT+=step;
  101.            sound(1000);
  102.            delay(0);
  103.            nosound();
  104.           }//if
  105.          }//else
  106.         if (pbutHeat1->on)
  107.          {
  108.           if (!butHeater->on)
  109.            {
  110.         HeatON;            // If heater is off
  111.         butHeater->On();    //  switch it on
  112.         delay(500);
  113.         }//if
  114.           else if ( !(--counter) ) // decr counter and
  115.             {                  // if counter==0
  116.              counter=heatIntensity; // reload it
  117.              HeatOFF;                // and switch heater OFF
  118.              butHeater->Off();
  119.              delay(500);
  120.              }//else_if
  121.          }//if(pbpHeat->on)
  122.             else
  123.                 HeatOFF;
  124.       break;
  125.   case 10:        //--- Stop Tdep measurement
  126.       HeatOFF;
  127.       butHeater->Off();
  128.       measInProgress=0;
  129.       statusTdep=11;    // switch backgr measurement in idle mode
  130.       fclose( dat);
  131.       if ( !Confirm(" Save data file ? ", YES) )
  132.          unlink( nameTdepDat);
  133.       grTdep1.Remove();
  134.       break;
  135.   case 11:;        //--- Dummy entry. Measurement is idle.
  136.  }
  137. }
  138.  
  139. //--------------------------- tib proc HEATER INTENSITY-----
  140. int far  tibpIntens(int Intensity)
  141. {
  142. counter = Intensity;
  143. return Intensity;
  144. }
  145.  
  146. void far bpHeat1(void)
  147. {
  148.  pbutHeat1->Invert();
  149. }
  150.  
  151.  
  152. //------------------------------ Tdep BUTTON PROCEDURE ------
  153. void far  bpTdep(void)
  154. {
  155. int X0=Tdependance->x0, Y0=Tdependance->y0p+5;
  156.  
  157. statusTdep=11;        // No measurement - idle backgr. proc
  158.  
  159. butsystem bsTdep;
  160.  
  161.  
  162.  TSInbox<double> *ptibMinT = new TSInbox<double>
  163.     ( X0, Y0, "T min :",
  164.       7, &minT,"%lf","%5.1f", NULL,SMALL_FONT, 4,plaquecoldflt,ibxcolLum);
  165.  
  166.  TSInbox<double> *ptibMaxT= new TSInbox<double>
  167.     ( ptibMinT->xmax, Y0, "T max :",
  168.       7, &maxT,"%lf","%5.1f", NULL,SMALL_FONT, 4,plaquecoldflt,ibxcolLum);
  169.  
  170.  TSInbox<double> *ptibStep= new TSInbox<double>
  171.     (  ptibMaxT->xmax, Y0, "Step :",
  172.       7, &step,"%lf","%5.2f", NULL,SMALL_FONT, 4,plaquecoldflt,ibxcolLum);
  173.  
  174.  Y0 = ptibMaxT->ymax;
  175.  
  176. #define chBUTSHF     10
  177.  
  178. butgrp gr1( X0+20, Y0+16, 46, 18, VERT);
  179.   pbutHeat1 = new indbutton("Heater",'H','h', bpHeat1, 4, SMALL_FONT,4);
  180.  
  181.  TSInbox<int> *ptibIntens= new TSInbox<int>
  182.     ( pbutHeat1->xmax+5,  Y0, "Heat Intns :",
  183.       5, &heatIntensity,"%d","%d", tibpIntens,SMALL_FONT, 4,plaquecoldflt,ibxcolLum);
  184.  
  185. _Indicator    _indN1(
  186.         ptibMaxT->xmax, Y0,FIXED,"N",
  187.         5,"%d",    // width of disp in chars,format
  188.         UNFRAMED,procNULL,
  189.         0,1,        //font and size of number
  190.         SMALL_FONT,4,    //font and size of title
  191.         plaquecoldflt,LUMind);
  192.  
  193.  indN1=&_indN1;
  194.  
  195. int axmax=ptibStep->xmax;
  196.     //---------------- Buttons ------
  197.  
  198. butgrp gr2( X0+chBUTSHF,_indN1.ymax+6,(axmax-X0-2*chBUTSHF)>>1,20);
  199.   button butStop("stoP measurement",'P','p',bpStopTdep,SMALL_FONT,4);
  200.   button butStart("Start measurement",'S','s',bpStartTdep,SMALL_FONT,4);
  201.  
  202. Tdependance->ChangeSize(axmax-X0,butStart.ymax-Tdependance->y0+chBUTSHF);// size of board
  203.  
  204.     //---------------- Paint whole board
  205. Tdependance->Paint();
  206.  
  207. ptibMinT->Paint();
  208. ptibMaxT->Paint();
  209. ptibStep->Paint();
  210. ptibIntens->Paint();
  211. _indN1.Paint();
  212.  
  213. ptibMinT->Refresh();
  214. ptibMaxT->Refresh();
  215. ptibStep->Refresh();
  216. ptibIntens->Refresh();
  217.  
  218.  
  219. gr1.Paint();
  220. gr2.Paint();
  221.  
  222. bsTdep.NextButton();
  223. do
  224.   bsTdep.Loop(TdepBackgr);
  225. while(measInProgress);
  226.  
  227. Tdependance->Remove();
  228. Tdependance->MkActive();
  229. object::RepaintScr();
  230.  
  231. delete ptibMinT;
  232. delete ptibMaxT;
  233. delete ptibStep;
  234. delete ptibIntens;
  235.  
  236. }//--------- bpTdep(void)
  237.  
  238.         //------ T-DEPENDANCE BUTTON PROCs ----
  239.  
  240.  
  241.  
  242. /*
  243. //------------------------------------ N -----
  244. void far  bpNTdep(void)
  245. {
  246. Inbox EnterN(maxx>>2,maxy>>2,POPUP,"Enter N",40/*size of box*/);
  247.  EnterN.Paint();
  248.  do
  249.  {
  250.   EnterN.cls();
  251.   EnterN.Put("Number of samples =",1);
  252.  }while ( !( EnterN.Scanf("%d",&N1) ) );
  253.  EnterN.Remove();
  254.  indN1->cls();indN1->Put(N1);
  255. }
  256. */
  257. //------------------------------------ START -----
  258. void far  bpStartTdep(void)
  259. {
  260. if (!measInProgress)
  261.  {
  262.   statusTdep=0;    // start backgr measurement
  263.   _maxT=maxT;
  264.   _minT=minT;
  265.  }
  266. }
  267.  
  268. //------------------------------------ STOP -----
  269. void far  bpStopTdep(void)
  270. {
  271. if (measInProgress)
  272.  {statusTdep=10;}    // switch backgr measurement in stop mode
  273. }
  274. //+++++++++++++++++++++++++++++++++++++++++++++++++++++
  275. //------------------------------ T-DEPENDANCE GRAPH -----
  276.  
  277. void far  bpTdepGraph(void)
  278. {
  279. float Temp0,Temp1;
  280. float a10,a11,b10,b11;
  281.  
  282.  if ( (dat = fopen(nameTdepDat,"rt")) == NULL )
  283.    DisplayErrorMessage("No measurement has been made yet");
  284.  else
  285.  {
  286.   find_ch('=');
  287.   fscanf(dat,"%lf",&minT);
  288.   find_ch('=');
  289.   fscanf(dat,"%lf",&maxT);
  290.   find_ch('=');
  291.   fscanf(dat,"%lf",&step);
  292.   find_ch('@');
  293.  
  294.  Graph<float,float>  grTdep(
  295.     x0s,y0s,PERM,nameTdepDat,
  296.     15,12,    /* number of x & y div.            */
  297.     25,20,    /* number of pixels in every div.    */
  298.  
  299.     minT,-2.5,    /* values of x,y at origin    */
  300.     (maxT-minT)/15.,5./12.,    /* values of x,y div.        */
  301.                       // Hereafter defaults are used
  302.     procDummy,
  303.     "Temperature","A1(red) B1(yellow)",    /* text on the axises*/
  304.     "%.1f","%.2f");             /* format of values on divisions*/
  305.  
  306.   grTdep.Paint();
  307.   while ( fscanf(dat,"%f%lf%lf",&Temp0,&a1,&b1) != EOF );
  308.   grTdep.PutDot(Temp0,a10,RED);
  309.   grTdep.PutDot(Temp0,b10,YELLOW);
  310.   while ( fscanf(dat,"%f%f%f",&Temp1,&a11,&b11)!=EOF )
  311.   {
  312.    grTdep.PutLine(Temp0,a10,Temp1,a11,RED);
  313.    grTdep.PutLine(Temp0,b10,Temp1,b11,YELLOW);
  314.    a10=a11; b10=b11;
  315.    Temp0=Temp1;
  316.    }
  317.   fclose(dat);
  318.   getch();
  319.   grTdep.Remove();
  320.   }//-- else
  321. }//--------------- END of bpTdepGraph(void) ---------
  322.